﻿using MetadataDesignerLibrary;
using Newtonsoft.Json.Linq;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;

namespace MetadataDesignerTests
{
    internal class Program
    {
        private const string _assemblyPath = "../../../../Samples/bin/Debug/net7.0/Samples.dll";

        private static void Main(string[] args)
        {
            JArray result = new JArray();
            using (FileStream fs = new FileStream(_assemblyPath, FileMode.Open, FileAccess.Read))
            {
                using (PEReader peReader = new PEReader(fs))
                {
                    MetadataReader reader = peReader.GetMetadataReader();
                    foreach (var item in reader.TypeDefinitions)
                    {
                        result.Add(new TypeDefinitionRule(reader, item).ToJson(reader));
                    }
                }
            }

            using (FileStream outputFile = new FileStream("output.json", FileMode.Create))
            {
                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    writer.Write(result.ToString());
                }
            }
        }
    }
}